<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
      layout:decorate="~{admin/layout}">
<body>

<div  class="content-wrap" layout:fragment="content">
    <main id="content" class="content" role="main">
        <ol class="breadcrumb">
            <li>日志管理</li>
            <li class="active">日志列表</li>
        </ol>
        <div>
            <div class="clearfix">
                <ul class="nav nav-tabs pull-xs-left" id="myTab" role="tablist">
                    <li class="nav-item">
                        <a class="nav-link active" id="home-tab" data-toggle="tab" href="#basic" role="tab" aria-controls="basic" aria-expanded="true" onclick="index0()">用户登录日志</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" id="profile-tab" data-toggle="tab" href="#assumtion" role="tab" aria-controls="assumtion" aria-expanded="false" onclick="index1()">入库日志</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link"  data-toggle="tab" href="#dropdown1" role="tab" aria-controls="dropdown1" aria-expanded="false" onclick="index2()">出库日志</a>
                    </li>
                </ul>
            </div>
            <div class="tab-content mb-lg" id="myTabContent">
                <div class="layui-inline">
                    <label class="layui-form-label">日期范围</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="test6"  lay-key="7">
                        <button  onclick="exportExcel()">导出</button>
                    </div>
                </div>
                <script>
                    layui.use('laydate', function(){
                        var laydate = layui.laydate;
                        //执行一个laydate实例
                        laydate.render({
                            elem: '#test6',
                            range: true   //指定元素
                        });
                    });
                    var index=0;
                    function index0() {
                        index=0;
                    }
                    function index1() {
                        index=1;
                    }
                    function index2() {
                        index=2;
                    }
                    function exportExcel() {
                        $.ajax({
                            url: "/admin/log/export",
                            type: 'GET',
                            data:{"index":index,"time":$("#test6").val()},
                            async: false,
                            success: function (data) {
                                if(data=="error"){
                                    alert("未找到时间段内数据");
                                }else {
                                    location.href = "/"+data;
                                }

                            },
                            error: function (xhr) {
                                console.log("error")
                            }
                        });
                    }
                </script>
                <div role="tabpanel" class="tab-pane clearfix active" id="basic" aria-labelledby="basic-tab" aria-expanded="true">
                    <div class="mt">
                        <table id="datatable-table"  class="table table-striped table-hover">
                            <thead>
                            <tr>
                                <th>用户名</th>
                                <th>动作</th>
                                <th class="no-sort hidden-sm-down">IP</th>
                                <th class="hidden-sm-down">时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="log:${log}">
                                <td th:text="${log.username}"></td>
                                <td th:text="${log.operation}"></td>
                                <td th:text="${log.IP}"></td>
                                <td th:text="*{#dates.format(log.operationtime,'yyyy-MM-dd HH:mm:ss')}"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="tab-pane" id="assumtion" role="tabpanel" aria-labelledby="assumtion-tab" aria-expanded="false">
                    <div class="mt">
                        <table class="table table-striped table-hover">
                            <thead>
                            <tr>
                                <th class="no-sort hidden-sm-down">苗木数量</th>
                                <th class="hidden-sm-down">树种</th>
                                <th class="no-sort">胸径</th>
                                <th class="no-sort">高度</th>
                                <th class="no-sort">产地</th>
                                <th class="no-sort">入库时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="trees :${treesput}">
                                <td th:text="${trees.number}"></td>
                                <td th:text="${trees.treeSpecies}"></td>
                                <td class="check"  th:text="${trees.chestBreadth}"></td>
                                <td  class="check" th:text="${trees.height}"></td>
                                <td th:text="${trees.location}"></td>
                                <td th:text="*{#dates.format(trees.putNurseryTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="tab-pane" id="dropdown1" role="tabpanel" aria-labelledby="dropdown1-tab" aria-expanded="false">
                    <div class="mt">
                        <table class="table table-striped table-hover">
                            <thead>
                            <tr>
                                <th class="no-sort hidden-sm-down">苗木数量</th>
                                <th class="hidden-sm-down">树种</th>
                                <th class="no-sort">胸径</th>
                                <th class="no-sort">高度</th>
                                <th class="no-sort">去向</th>
                                <th class="no-sort">出库时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="trees :${treesout}">
                                <td th:text="${trees.number}"></td>
                                <td th:text="${trees.treeSpecies}"></td>
                                <td class="check" th:text="${trees.chestBreadth}"></td>
                                <td  class="check" th:text="${trees.height}"></td>
                                <td  class="check" th:text="${trees.direction}"></td>
                                <td th:text="*{#dates.format(trees.outWarehouseTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

            </div>
        </div>
        <script>
            checknumber();
        </script>
    </main>
</div>
</body>
</html>